package com.example.glide_pre_demo;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.example.glide_pre_demo.blur.BlurBuilder;
import com.example.glide_pre_demo.manager.ImageLoader;

/**
 * @author carlos
 * @date 2016/5/17
 */
public class BlurActivity extends Activity {

    private ImageView mIvOrigin;
    private ImageView mIvBlur;

    private SimpleTarget mTarget;
    private SimpleTarget mTargetBlur;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_blur);
        initView();
        initData();
        loadImage();
    }

    private void initData() {
        mTarget = new SimpleTarget<Bitmap>(200, 200) {
            @Override
            public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
                mIvOrigin.setImageBitmap(bitmap);
            }
        };

        mTargetBlur = new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
                bitmap = BlurBuilder.blur(MyApplication.getAppContext(), bitmap);
                mIvBlur.setImageBitmap(bitmap);
            }
        };
    }

    private void initView() {
        mIvOrigin = (ImageView) findViewById(R.id.iv_origin);
        mIvBlur = (ImageView) findViewById(R.id.iv_blur);
    }

    private void loadImage() {
        ImageLoader.loadFromUrl(MyApplication.getAppContext(),
                "http://tse1.mm.bing.net/th?id=OIP.M7dd4bf5a58e8f00643718c7a69eb4338o0&pid=15.1",
                mTarget);
        ImageLoader.loadFromUrl(MyApplication.getAppContext(),
                "http://tse1.mm.bing.net/th?id=OIP.M7dd4bf5a58e8f00643718c7a69eb4338o0&pid=15.1",
                mTargetBlur);
    }
}